<template>
	<view class="hexiao">
		<headertop title="核销" str1="oridei" :back1="back1"></headertop>
		<view class="hexiaoback">

		</view>
		<view class="orderinfo">
			<view class="center">
				<view class="toplinebox">
					<view class="dingdanbianh">
						<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/微信图片_20250429143332.png"
							mode=""></image>
						<span>订单编号：</span> {{contentobj.order.order_no}}
					</view>
					<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11457@2x.png" class="checkbox"
						mode=""></image>
				</view>

				<view class="infoline" v-for="item in contentobj.goods" :key="item.id" v-if="contentobj.type==3">
					<image :src="item.image" class="leftimg" mode=""></image>
					<view class="texts">
						<view class="t1">
							<view class="gubox" v-if="item.typename=='固'">
								固
							</view>
							<span>{{item.cname}}</span>
						</view>
						<view class="t2">
							{{item.detail}}
						</view>
					</view>
				</view>

				<view class="infoline" v-for="item in contentobj.goods" :key="item.id" v-if="contentobj.type!=3">
					<image :src="item.image" class="leftimg" mode=""></image>
					<view class="texts">
						<view class="t1">
							<span>{{item.title}}</span>
						</view>
						<view class="t2">
							{{item.detail}}
						</view>
					</view>
				</view>


				<view class="yuyueinfo">
					<view class="texts1">
						<span v-if="contentobj.type==3"> 预约人：{{contentobj.order.username}}</span>
						<span v-else> 联系人：{{contentobj.order.username}}</span>
					</view>
					<view class="texts1" v-if="contentobj.type==3">
						<span>预约电话：{{contentobj.order.telphone}}</span>
					</view>
					<view class="texts1" v-else style="margin-bottom: 30rpx;">
						<span>联系电话：{{contentobj.order.telphone}}</span>
					</view>

					<!-- 	<view class="texts1" style="margin-bottom: 28rpx;" v-if="contentobj.type==2||contentobj.type==4">
						<span>租用时间：{{timestampfun(contentobj.order.createtime*1000)}}</span>
					</view> -->

					<view class="texts1" style="margin-bottom: 28rpx;" v-if="contentobj.type==3">
						<span>预约时间：{{contentobj.order.datetime}}
							（{{contentobj.order.starttime}}-{{contentobj.order.endtime}}）</span>
					</view>
				</view>
			</view>
		</view>
		<view class="zhuangtaibox">
			<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Rectangle 24316@2x.png"
				class="zhuangtaiboximg" mode=""></image>
			<view class="linecenter">
				<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/image 59@2x.png" mode=""></image>
				<view class="statustext" v-if="contentobj.type==3">
					当前核销状态：{{statustext(contentobj.order.status)}}
				</view>
				<view class="statustext" v-if="contentobj.type==2||contentobj.type==4">
					当前核销状态：{{statustext1(contentobj.order.status)}}
				</view>
				<view class="statustext" v-if="contentobj.type==1">
					当前核销状态：{{statustext2(contentobj.order.status)}}
				</view>
			</view>
		</view>
		<view class="fixedbox">
			<view class="centerbox" @click="hexiaoqueren">
				确认核销
			</view>
		</view>
	</view>
</template>

<script setup>
	import headertop from '@/components/header.vue'
	import {
		onPageScroll,
		onLoad
	} from "@dcloudio/uni-app";
	import {
		ref
	} from 'vue'
	import {
		hexiao1
	} from "@/api/my.js"
	const back1 = ref('')
	const contentobj = ref({})
	onPageScroll((e) => {
		console.log(e, 'eeeeeeeeeeeeeee');
		if (e.scrollTop > 100) {
			back1.value = '#84BD78'
		} else {
			back1.value = ''
		}
	})
	onLoad(() => {
		contentobj.value = uni.getStorageSync('hexiaoobj')
		console.log(contentobj.value, 'contentobj.valuecontentobj.valuecontentobj.value');
	})

	function hexiaoqueren() {
		uni.showModal({
			title: '提示', // 标题（可选）
			content: '确定要核销吗？', // 内容（可选）
			confirmText: '确定', // 确认按钮文字（可选，默认“确定”）
			cancelText: '取消', // 取消按钮文字（可选，默认“取消”）
			success: (res) => {
				if (res.confirm) {
					hexiao()
					// 执行确定后的逻辑
				} else if (res.cancel) {
					console.log('用户点击了取消');
					// 执行取消后的逻辑
				}
			},
			fail: (err) => {
				console.error('弹窗调用失败', err);
			}
		});
	}
	async function hexiao() {
		const res = await hexiao1({
			hxmao: contentobj.value.hxnum
		})
		console.log(res, 'res---------');
		if (res.code == 0) {
			uni.showToast({
				title: res.msg,
				icon: 'none'
			})
			return
		}
		if (res.data.code == 1) {
			setTimeout(() => {
				uni.showToast({
					title: '核销成功',
					icon: 'none'
				})
			}, 500)
			uni.navigateBack();
		}
	}


	function statustext(num) {
		if (num == 0) {
			return '待支付'
		} else if (num == 1) {
			return '待入营'
		} else if (num == 2) {
			return '露营中'
		} else if (num == 3) {
			return '待退还'
		} else if (num == 4) {
			return '退还中'
		} else if (num == 5) {
			return '已完成'
		} else if (num == 6) {
			return '已取消'
		} else if (num == 7) {
			return '可退压'
		}
	}

	function statustext1(num) {
		if (num == 0) {
			return '待支付'
		} else if (num == 1) {
			return '待核销'
		} else if (num == 2) {
			return '租赁中'
		} else if (num == 3) {
			return '待退还'
		} else if (num == 4) {
			return '退还中'
		} else if (num == 5) {
			return '已完成'
		} else if (num == 6) {
			return '已取消'
		} else if (num == 7) {
			return '可退押'
		}
	}

	function statustext2(num) {
		if (num == 0) {
			return '待支付'
		} else if (num == 1) {
			return '待核销'
		} else if (num == 2) {
			return '待发货'
		} else if (num == 3) {
			return '待收货'
		} else if (num == 4) {
			return '已取消'
		} else if (num == 5) {
			return '已完成'
		}
	}

	function timestampfun(time) {
		const date = new Date(time);
		const year = date.getFullYear();
		const month = String(date.getMonth() + 1).padStart(2, "0");
		const day = String(date.getDate()).padStart(2, "0");
		const hours = String(date.getHours()).padStart(2, "0");
		const minutes = String(date.getMinutes()).padStart(2, "0");
		const seconds = String(date.getSeconds()).padStart(2, "0");
		const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
		return formattedDate;
	}
</script>

<style lang="scss">
	page {
		background: #F7F8FA;
	}

	.hexiao {
		width: 100%;
		overflow: hidden;
		position: relative;

		.fixedbox {
			width: 100%;
			height: 210rpx;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			overflow: hidden;
			position: fixed;
			bottom: 0%;

			.centerbox {
				width: 686rpx;
				height: 88rpx;
				background: #7EBC79;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				text-align: center;
				line-height: 88rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: center;
				margin: 30rpx auto;
			}
		}

		.hexiaoback {
			width: 100%;
			height: 530rpx;
			background: linear-gradient(180deg, #84BD78 0%, rgba(132, 189, 120, 0) 100%);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			position: absolute;
			z-index: -1;
		}

		.zhuangtaibox {
			width: 686rpx;
			margin: auto;
			margin-top: 28rpx;
			overflow: hidden;
			height: 112rpx;
			position: relative;

			.zhuangtaiboximg {
				width: 686rpx;
				position: absolute;
				z-index: -1;
				height: 112rpx;

			}

			.linecenter {
				display: flex;
				align-items: center;

				image {
					width: 116rpx;
					height: 100rpx;
					margin-left: 46rpx;
				}

				.statustext {
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 32rpx;
					color: #76AA25;
					margin-left: 22rpx;
				}
			}
		}

		.orderinfo {
			width: 686rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.15);
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			margin: auto;
			margin-top: 190rpx;
			overflow: hidden;

			.center {
				width: 630rpx;
				margin: auto;

				.yuyueinfo {
					width: 100%;
					overflow: hidden;
					margin-top: 28rpx;
					border-top: 2rpx solid #F2F3F5;

					.texts1 {
						width: 100%;
						align-items: center;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #1D2129;
						display: flex;
						margin-top: 24rpx;
					}
				}

				.infoline {
					width: 100%;
					display: flex;
					margin-top: 28rpx;

					.leftimg {
						width: 166rpx;
						height: 148rpx;
						border-radius: 20rpx 20rpx 20rpx 20rpx;
					}

					.texts {
						width: 358rpx;
						margin-left: 16rpx;

						.t2 {
							width: 358rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 28rpx;
							color: #000000;
							white-space: nowrap;
							/* 禁止换行 */
							overflow: hidden;
							/* 隐藏溢出内容 */
							text-overflow: ellipsis;
							margin-top: 28rpx;
							/* 超出用省略号表示 */
						}

						.t1 {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 32rpx;
							color: #1D2129;
							display: flex;
							align-items: center;

							.gubox {
								width: 48rpx;
								height: 32rpx;
								background: #7EBC79;
								border-radius: 4rpx 16rpx 4rpx 16rpx;
								line-height: 32rpx;
								font-family: PingFang SC, PingFang SC;
								font-weight: 500;
								font-size: 24rpx;
								color: #FFFFFF;
								text-align: center;
								margin-right: 8rpx;
							}
						}
					}
				}

				.toplinebox {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 24rpx;

					.dingdanbianh {
						font-weight: 500;
						font-size: 28rpx;
						color: #1D2129;
						display: flex;
						align-items: center;

						image {
							height: 28rpx;
							margin-right: 12rpx;
							width: 24.03rpx;
						}
					}

					.checkbox {
						width: 40rpx;
						height: 40rpx;
					}
				}
			}
		}
	}
</style>